(function(){"use strict";BX.namespace("BX.Landing.UI.Field");var t=BX.Landing.Utils.setTextContent;var i=BX.Landing.Utils.escapeText;var e=BX.Landing.Utils.data;var n=BX.Landing.Utils.offsetTop;var s=BX.Landing.Utils.offsetLeft;BX.Landing.UI.Field.Dropdown=function(i){this.items="items"in i&&i.items?i.items:{};BX.Landing.UI.Field.BaseField.apply(this,arguments);this.setEventNamespace("BX.Landing.UI.Field.Dropdown");this.subscribeFromOptions(BX.Landing.UI.Component.fetchEventsFromOptions(i));this.onChangeHandler=typeof i.onChange==="function"?i.onChange:function(){};this.frame=typeof i.frame==="object"?i.frame:null;this.layout.classList.add("landing-ui-field-dropdown");this.popup=null;this.input.addEventListener("click",this.onInputClick.bind(this));this.classForTextNode=i.classForTextNode;document.addEventListener("click",this.onDocumentClick.bind(this));var n=BX.Landing.PageObject.getRootWindow();n.document.addEventListener("click",this.onDocumentClick.bind(this));if(i.hint){var s=this.layout.querySelector(".landing-ui-field-header");if(s){BX.Dom.append(top.BX.UI.Hint.createNode(i.hint),s)}}if(BX.type.isPlainObject(this.items)){var o=Object.keys(this.items);this.items=o.map((function(t){return{name:this.items[t],value:t}}),this)}if(BX.Type.isArrayFilled(this.items)){t(this.input,this.items[0].name,this.classForTextNode);e(this.input,"value",this.items[0].value)}else{t(this.input,BX.Landing.Loc.getMessage("LANDING_DROPDOWN_NOT_FILLED"));e(this.input,"value","")}if(this.content!==""){setTimeout((()=>{this.emit("onInit",this.items[this.content])}),0);this.setValue(this.content)}};BX.Landing.UI.Field.Dropdown.prototype={constructor:BX.Landing.UI.Field.Dropdown,__proto__:BX.Landing.UI.Field.BaseField.prototype,onInputClick:function(t){t.stopPropagation();if(!this.popup||!this.contentRoot&&this.popupRoot&&!this.popupRoot.contains(this.popup.popupWindow.popupContainer)){var e=[];this.items.forEach((function(t){if(t.hidden!==true){e.push(t)}}));var o;if(this.options.maxHeight){o=this.options.maxHeight}else{o=196}e=e.map((function(t){if(t.delimiter){return{delimiter:t.delimiter}}return{html:t.html,text:!t.html?i(t.name):undefined,onclick:function(){this.onItemClick(t)}.bind(this),className:t.className}}),this);this.popup=new BX.PopupMenuWindow({id:"dropdown_"+ +new Date,bindElement:this.input,bindOptions:{forceBindPosition:true},targetContainer:this.contentRoot,maxHeight:o,items:e,events:{onPopupClose:function(){this.input.classList.remove("landing-ui-active");this.layout.classList.remove("landing-ui-active")}.bind(this)},className:this.options.className,angle:true});if(!this.contentRoot){this.popupRoot=this.layout.parentElement.parentElement.parentElement;this.popupRoot.appendChild(this.popup.popupWindow.popupContainer);this.popupRoot.style.position="relative"}}this.layout.classList.add("landing-ui-active");this.input.classList.add("landing-ui-active");if(this.popup.popupWindow.isShown()){this.popup.close()}else{this.popup.show()}var p=this.input.getBoundingClientRect();if(!this.contentRoot){var a=s(this.input,this.popupRoot);var u=n(this.input,this.popupRoot);this.popup.popupWindow.popupContainer.style.top=u+p.height+"px";this.popup.popupWindow.popupContainer.style.left=a+"px"}this.popup.popupWindow.popupContainer.style.width=p.width+"px"},onItemClick:function(i){t(this.input,i.name,this.classForTextNode);e(this.input,"value",i.value);this.popup.close();this.onChangeHandler(i.value,this.items,this.postfix,this.property);this.onValueChangeHandler(this);BX.fireEvent(this.input,"input");this.emit("onChange",i)},getValue:function(){var t=this.input.dataset.value;if(t!=="undefined"&&typeof t!=="undefined"){return t}if(BX.Type.isArrayFilled(this.items)){return this.items[0].value}},setValue:function(i,n){this.items.forEach((function(s){if(i==s.value){t(this.input,s.name,this.classForTextNode);e(this.input,"value",s.value);if(n){setTimeout((()=>{this.emit("onInit",s)}),0)}}}),this)},onFrameLoad:function(){const t=this.frame.document.querySelector(this.selector);if(t){const i=this.items.find((i=>t.classList.contains(i.value)));if(i){this.setValue(i.value,true)}}},isChanged:function(){return this.content!=this.getValue()},onDocumentClick:function(){if(this.popup){this.popup.close()}}}})();
//# sourceMappingURL=dropdown_field.map.js